package com.noranj.web.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.noranj.web.shared.DocumentDTO;

public class DocumentListView extends Composite {

	private static DocumentListViewUiBinder uiBinder = GWT
			.create(DocumentListViewUiBinder.class);

	interface DocumentListViewUiBinder extends
			UiBinder<Widget, DocumentListView> {
	}

	@UiField
	VerticalPanel documentsPanel;
	private List<DocumentDTO> documentDTOs;

	public DocumentListView() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public DocumentListView(List<DocumentDTO> documentDTOs) {
		this();
		this.documentDTOs = documentDTOs;
		displayDocuments();
	}

	private void displayDocuments() {
		for (DocumentDTO documentDTO : documentDTOs) {
			documentsPanel.add(new DocumentRow(documentDTO.getTitle(),
			documentDTO.getDescription(), documentDTO.getCreatedOn()));
		}
	}

}
